package com.main;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;

import com.app.util.ReflectUtil;
import com.entity.Student;

public class Main {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
//		Map<String, Object> classToMap = ReflectUtil.classToMap(Student.class);
		
		
		Student stu = new Student();
		stu.setAge(11);
		stu.setName("A");
		
		Field[] declaredFields = stu.getClass().getDeclaredFields();
		for (Field f : declaredFields) {  
            Object v = invokeMethod(stu, f.getName());  
            System.out.println(f.getName() + "\t" + v + "\t" + f.getType());  
        }  
		System.out.println("1");
	}
	
	@SuppressWarnings("unchecked")  
    private static Object invokeMethod(Object owner, String methodName) throws Exception {  
        Class ownerClass = owner.getClass();  
        methodName = methodName.substring(0, 1).toUpperCase()  
                + methodName.substring(1);  
        Method method = null;  
        try {  
            method = ownerClass.getMethod("get" + methodName);  
        } catch (SecurityException e) {  
        } catch (NoSuchMethodException e) {  
            return " can't find 'get" + methodName + "' method";  
        }  
        return method.invoke(owner);  
    }  

}
